| Conditions | 8 |
| Paths | 80 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | 'use strict' |
||
| 10 | module.exports = function (kit, slug) { |
||
| 11 | inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')) |
||
| 12 | var questions = [] |
||
| 13 | |||
| 14 | if (!kit && !slug && fs.existsSync('module.json')) { |
||
| 15 | output.warn('Are you sure you want to create a new module here? There already seems to be one in ' + |
||
| 16 | 'this directory. Instead, did you mean to type `inc run`?\n') |
||
| 17 | } else { |
||
| 18 | output.newline() |
||
| 19 | } |
||
| 20 | |||
| 21 | if (!slug || !slug.length) { |
||
| 22 | var userName = (util.getSystemUsername() || 'user').toLowerCase() |
||
| 23 | questions.push({ |
||
| 24 | type: 'input', |
||
| 25 | name: 'slug', |
||
| 26 | default: userName + '/my-module', |
||
| 27 | message: 'What should we name this module?', |
||
| 28 | validate: function (value) { |
||
| 29 | if (value.match(/^([a-z0-9-]+\/)?[a-z0-9-]+$/)) { |
||
| 30 | return true |
||
| 31 | } |
||
| 32 | |||
| 33 | return 'Module name should only contain lowercase letters, numbers and dashes.' |
||
| 34 | } |
||
| 35 | }) |
||
| 36 | } |
||
| 37 | |||
| 38 | if (!kit || !kit.length) { |
||
| 39 | questions.push({ |
||
| 40 | type: 'autocomplete', |
||
| 41 | name: 'kit', |
||
| 42 | message: 'What template would you like to use?', |
||
| 43 | source: function (answers, input) { |
||
| 44 | return new Promise(function (resolve) { |
||
| 45 | Kits.list(function (list) { |
||
| 46 | resolve(input && input.length ? list.filter(function (value) { |
||
| 47 | return value.indexOf(input) >= 0 |
||
| 48 | }) : list) |
||
| 49 | }) |
||
| 50 | }) |
||
| 51 | }, |
||
| 52 | default: 'basic' |
||
| 53 | }) |
||
| 54 | } |
||
| 55 | |||
| 56 | // Prompt questions |
||
| 57 | inquirer.prompt(questions).then(function (answers) { |
||
| 58 | output.newline() |
||
| 59 | Kit.create(answers.kit || kit, answers.slug || slug) |
||
| 60 | }) |
||
| 61 | } |
||
| 62 |